package com.test.design.material.materialdesign;

import android.content.Context;

import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.view.ViewCompat;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Button;

/**
 * author:harisucici on 2018/8/1 09:21
 * email:harisucici@gmail.com
 * name:
 * todo:
 */
public class MyBehavior extends CoordinatorLayout.Behavior<View> {

    public MyBehavior(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean layoutDependsOn(CoordinatorLayout parent, View child, View dependency) {
        return dependency instanceof Button; //关心所有Button的变化。
//        return dependency.getId()==R.id.Btn; //关心id为R.id.Btn的变化。
    }

    @Override
    public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) {
        int offset = dependency.getTop();
        ViewCompat.offsetTopAndBottom(child, -offset);
        return true;
    }
}